<template>
    <div>
        <!-- 面包屑导航区域 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图区域 -->
    <el-card>
         <el-row :gutter="20">
        <el-col :span="8">
          <!-- 搜索与添加区域 -->
          <el-input placeholder="请输入内容"  clearable v-model="reqOrderData.query" clear @clear="clearForm()">
            <el-button slot="append" icon="el-icon-search" @click="search" title="搜索"></el-button>
          </el-input>
        </el-col>
      </el-row>
 <el-table :data="ordersForm"
    stripe border
    style="width: 100%">
    <el-table-column type="index"></el-table-column>
    <el-table-column prop="order_number" label="订单编号" width="280">
    </el-table-column>
    <el-table-column prop="order_price" label="订单价格" width="100">
    </el-table-column>
    <el-table-column prop="pay_status" label="是否付款">
       <template slot-scope="scope">
           <el-tag v-if="scope.row.pay_status === '0'"
           type="danger">未付款</el-tag>
        <el-tag v-else type="success">已付款</el-tag>
       </template>
    </el-table-column>
     <el-table-column prop="is_send" label="是否发货">
    </el-table-column>
     <el-table-column prop="create_time" label="下单时间">
         <template slot-scope="scope">
             {{scope.row.create_time*1060 | dateFormat}}
         </template>
    </el-table-column>
     <el-table-column  label="操作">
         <template slot-scope="scope">
             <el-button icon="el-icon-edit" type="primary"
             size="mini" @click="editOrders(scope.row)"></el-button>
             <el-button icon="el-icon-location" type="success"
             size="mini" @click="showprogress(scope.row)"></el-button>
         </template>
    </el-table-column>
  </el-table>
  <!-- 分页组件 -->
   <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="reqOrderData.pagenum"
      :page-sizes="[5, 10, 20, 30]"
      :page-size="reqOrderData.pagesize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="this.total" background>
    </el-pagination>
    </el-card>
     <!-- 修改订单商品的对话框 -->
     <el-dialog title="修改地址" :visible.sync="editOrdersVisible"
  width="50%" @close="editOrdersClosed">
<el-form :model="editOrdersForm" :rules="editOrderRules" ref="editOrdersRef"
 label-width="100px">
  <el-form-item label="省市区/县:" prop="province">
 <el-cascader v-model="editOrdersForm.address1" :options="cityData"
    :props="{ expandTrigger: 'hover', value: 'value', label: 'label',
     children: 'children'}"
    clearable @change="handleChange"></el-cascader>
  </el-form-item>
   <el-form-item label="详细地址" prop="xiangxi">
    <el-input v-model="editOrdersForm.address2"></el-input>
  </el-form-item>
</el-form>
 <span slot="footer" class="dialog-footer">
    <el-button @click="editOrdersVisible = false">取 消</el-button>
    <el-button type="primary" @click="editOrdersTrue">确 定</el-button>
  </span>
</el-dialog>
<!-- 查看物流信息弹框 -->
 <el-dialog title="物流进度" :visible.sync="progressVisible"
  width="50%" >
<el-timeline>
    <el-timeline-item
      v-for="(activity, index) in wuliudata"
      :key="index"
      :timestamp="activity.time">
      {{activity.context}}
    </el-timeline-item>
  </el-timeline>
</el-dialog>
    </div>
</template>
<script>
import citydata from './citydata.js'
import wuliu from './wuliu.js'
export default {
  data () {
    return {
      reqOrderData: { // 请求参数（查询对象)
        query: '',
        pagenum: 1,
        pagesize: 5,
        user_id: '',
        pay_status: '',
        is_send: '',
        order_fapiao_title: '',
        order_fapiao_company: '',
        order_fapiao_content: '',
        onsignee_addr: '' // 发货地址
      },
      ordersForm: {}, // 存放请求到的订单数据
      total: 0, // 总的数据条数
      editOrdersVisible: false,
      editOrdersForm: {
        address1: [],
        adderss2: []
      }, // 编辑地址的数据
      editOrderRules: {
        province: [
          { required: true, message: '请选择省市区', trigger: 'blur' }
        ],
        xiangxi: [
          { required: true, message: '请填写详细地址', trigger: 'blur' }
        ]
      }, // 校验规则
      cityData: citydata,
      progressVisible: false,
      wuliudata: wuliu // 物流信息数据
    }
  },
  methods: {
    async getOrders () {
      const { data: res } = await this.$http.get('orders', { params: this.reqOrderData });
      if (res.meta.status !== 200) {
        return this.$message.error('请求订单数据失败');
      }
      this.ordersForm = res.data.goods;
      this.total = res.data.total
      console.log(this.ordersForm)
    },
    clearForm () {
      this.getOrders();
    },
    search () {
      this.getOrders();
    },
    handleSizeChange (newsize) {
      this.reqOrderData.pagesize = newsize;
      this.getOrders();
    },
    handleCurrentChange (newnum) {
      this.reqOrderData.pagenum = newnum;
      this.getOrders();
    },
    editOrdersClosed () {
      // 对话框关闭时候出发
      this.$refs.editOrdersRef.resetFields();
    },
    editOrdersTrue () {
      // 修改地址确认按钮
      this.editOrdersVisible = false;
    },
    editOrders () {
      // 编辑地址打开修改对话框
      this.editOrdersVisible = true;
    },
    handleChange () {
      // 级联选择框发生变化时候触发
    },
    async showprogress () {
      // 展示物流进度
      /*  const { data: res } = await this.$http.get('/kuaidi/804909574412544580')
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流信息失败');
      }
      this.wuliudata = res.data; */
      console.log(this.wuliudata)
      this.progressVisible = true;
    }

  },
  created () {
    this.getOrders();
  }
}
</script>
<style lang="less" scoped>
.el-cascader{
    width: 100%;
}
</style>
